package graph.editor;

import java.awt.Dimension;
import java.util.*;
import javax.swing.*;
import javax.swing.plaf.ColorUIResource;


public class GraphEditor implements FramesController {

	public final static String MENU_FILE = "File";
	public final static String MENU_ITEM_NEW = "New";
	public final static String MENU_ITEM_CLOSE = "Close";
	public final static String MENU_ITEM_QUIT = "Quit";
	public final static String MENU_ITEM_LOAD = "Load";
	public final static String MENU_ITEM_SAVE = "Save";
	public final static String MENU_ITEM_RUN = "Run";
	public final static String MENU_ITEM_ABOUT = "About";
	public final static String MENU_ITEM_HELP = "Help";
	public final static String MENU_ITEM_COLOR = "Color";
	public final static String DIALOG_QUIT_MSG = "Do you really want to quit ?";
	public final static String DIALOG_QUIT_TITLE = "Quit ?";
	public final static String DIALOG_SAVE = "Save Successfull";
	public final static String DIALOG_SAVE_ERROR = "Can't Save";
	public final static String DIALOG_OPEN = "Open Successfull";
	public final static String DIALOG_OPEN_ERROR = "Can't opne this file";
	public final static String STRING_INPUT_WORD = "Input word";
	public final static String STRING_BUTTON_START = "Start";
	public final static String STRING_WORD_RECOGNIZE = "Word recognize";
	public final static String STRING_WORD = "Word can't recognize";
	public final static String TITLE = "Graph";
	public final static String STRING_ABOUT = "Luong Vinh Thao && Phan Nguyen Anh Vinh";
	
	private static final List<JFrame> frames = new ArrayList<JFrame>();

	public void quit() {
		int answer = JOptionPane.showConfirmDialog(null, DIALOG_QUIT_MSG,
				DIALOG_QUIT_TITLE, JOptionPane.YES_NO_OPTION);
		if (answer == JOptionPane.YES_OPTION) {
			System.exit(0);
		}
	}

	public JFrame createFrame() {
		JFrame frame = new GraphFrame(this);
		frame.setTitle(TITLE);
		int pos = 30 * (frames.size() % 5);
		frame.setLocation(pos, pos);
		frame.setPreferredSize(new Dimension(700, 800));
		frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
		frames.add(frame);
		return frame;
	}

	public void deleteFrame(JFrame frame) {
		if (frames.size() > 1) {
			frames.remove(frame);
			frame.dispose();
		} else {
			quit();
		}
	}

	public static void main(String[] args) {
		
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
//				 GraphFrame gf = (GraphFrame)new GraphEditor().createFrame();
				try {
					// Set System L&F
					//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
					UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
					//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
					
					// UIManager.getSystemLookAndFeelClassName("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"));

				} catch (UnsupportedLookAndFeelException e) {
					// handle exception
				} catch (ClassNotFoundException e) {
					// handle exception
				} catch (InstantiationException e) {
					// handle exception
				} catch (IllegalAccessException e) {
					// handle exception
				}
				JFrame.setDefaultLookAndFeelDecorated(true);
				new GraphEditor().createFrame(); // Create and show the GUI.

			}
		});
	}
}